<template>
    <div class="FlashingEntity">
        <cesium-viewer @viewerAlready="viewerAlready">
        </cesium-viewer>
    </div>
</template>

<script>
    import CesiumViewer from "../../CesiumViewer";
    export default {
        name: "FlashingEntity",
        //import引入的组件需要注入到对象中才能使用",
        components: {CesiumViewer},
        data() {
            //这里存放数据",
            return {};
        },
        //监听属性 类似于data概念",
        computed: {},
        //监控data中的数据变化",
        watch: {},
        //方法集合",
        methods: {
            viewerAlready(){
                //飞行到这个位子
                window.viewer.camera.flyTo({
                    destination : Cesium.Cartesian3.fromDegrees(117.217124,31.770777, 15000.0),
                    orientation: {
                        heading : Cesium.Math.toRadians(90.0), // east, default value is 0.0 (north) //东西南北朝向
                        pitch : Cesium.Math.toRadians(-90),    // default value (looking down)  //俯视仰视视觉
                        roll : 0.0                             // default value
                    },
                    duration:3//3秒到达战场
                });
                let x = 1;
                let flag = true;
                //添加billboard
                window.viewer.entities.add({
                    name:"",
                    position: Cesium.Cartesian3.fromDegrees(117.217124, 31.809777),
                    point : {
                        show : true, // default
                        color :new Cesium.CallbackProperty(function () {
                            if(flag){
                                x-=0.05;
                                if(x<=0){
                                    flag=false;
                                }
                            }else{
                                x+=0.05;
                                if(x>=1){
                                    flag=true;
                                }
                            }
                            return Cesium.Color.RED.withAlpha(x);
                        },false),
                        pixelSize : 10, // default: 1
                        outlineWidth :0
                    }
                });

                window.viewer.entities.add({
                    name:"",
                    position: Cesium.Cartesian3.fromDegrees(117.217124, 31.729777),
                    ellipse : {
                        semiMinorAxis : 2000.0,
                        semiMajorAxis : 2000.0,
                        height : 0,
                        material:new Cesium.ColorMaterialProperty(new Cesium.CallbackProperty(function () {
                            if(flag){
                                x=x-0.05;
                                if(x<=0){
                                    flag=false;
                                }
                            }else{
                                x=x+0.05;
                                if(x>=1){
                                    flag=true;
                                }
                            }
                            return Cesium.Color.BLUE.withAlpha(x);
                        },false))
                    }
                    });
                window.viewer.entities.add({
                    name: "box",
                    position: Cesium.Cartesian3.fromDegrees(117.217124, 31.785777,2500), //盒子中心位置
                    box: {
                        dimensions: new Cesium.Cartesian3(1000.0, 2000.0, 5000.0),
                        material: new Cesium.ColorMaterialProperty(
                                new Cesium.CallbackProperty(function () {
                                    if(flag){
                                        x=x-0.05;
                                        if(x<=0){
                                            flag=false;
                                        }
                                    }else{
                                        x=x+0.05;
                                        if(x>=1){
                                            flag=true;
                                        }
                                    }
                                    return Cesium.Color.GREENYELLOW.withAlpha(x);
                                },false)
                            ),
                        outline: true,
                        outlineColor: Cesium.Color.YELLOW,
                    },
                });
            }
        },
        //生命周期 - 创建之前",数据模型未加载,方法未加载,html模板未加载
        beforeCreate() {
        },

        //生命周期 - 创建完成（可以访问当前this实例）",数据模型已加载，方法已加载,html模板已加载,html模板未渲染
        created() {

        },
        //生命周期 - 挂载之前",html模板未渲染
        beforeMount() {

        },

        //生命周期 - 挂载完成（可以访问DOM元素）",html模板已渲染
        mounted() {

        },

        //生命周期 - 更新之前",数据模型已更新,html模板未更新
        beforeUpdate() {

        },
        //生命周期 - 更新之后",数据模型已更新,html模板已更新
        updated() {

        },
        //生命周期 - 销毁之前",
        beforeDestroy() {

        },
        destroyed() {

        },
        //生命周期 - 销毁完成",
        //如果页面有keep-alive缓存功能，这个函数会触发",
        activated() {

        },
    }

</script>

<style>

</style>

